﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;

namespace WebUI.Demo.Ashx
{
    /// <summary>
    /// ToDemoGetHtml 的摘要说明
    /// </summary>
    public class ToDemoGetHtml : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var file = context.Request.QueryString["file"];
            var uri = "http://" + context.Request.Url.Host + ":" + context.Request.Url.Port + "/demo/templates/" + file;
            // context.Response.Write(uri); return;
            var req = (HttpWebRequest)WebRequest.Create(uri);
            var res = (HttpWebResponse)req.GetResponse();
            var respStream = res.GetResponseStream();
            if (respStream == null) return;
            var reader = new StreamReader(respStream, Encoding.UTF8);
            context.Response.Write(reader.ReadToEnd());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}